/**
 * 飞机基类
 */
var BasePlane = require('./../BasePlane');
var BaseBullet = require('./../../Bullet/BaseBullet');

var EnumBody = require('./../../Enum/EnumBody');
var EnumPlane = require('./../../Enum/EnumPlane');

var EnumBullet = require('./../../Enum/EnumBullet');

var UtilGameObject = require('./../../../../../FrameWork/Utils/UtilGameObject');

module.exports = cc.Class(
{
    extends: BasePlane,

    properties:
    {
        prefabCarry:
        {
            default: null,
            type: cc.Prefab,
            displayName: '携带预设(本体死亡时会掉)'
        }
    },
    onLoad()
    {
        this._super();
        this.setEnumPlane(EnumPlane.ENEMY);
    },
    onCollisionEnter: function(other)
    {
        var body = this._super(other);
        if (null == body)
        {
            return;
        }

        var enumBody = body.getEnumBody();

        var isCheck = false;
        //碰撞到的类型
        if (EnumBody.PLANE == enumBody)
        {
            var plane = other.getComponent(BasePlane);
            if (null != plane && EnumPlane.MY == plane.getEnumPlane())
            {
                isCheck = true;
            }
        }
        else if (EnumBody.BULLET == enumBody)
        {
            var bullet = other.getComponent(BaseBullet);
            if (null != bullet && EnumBullet.MY == bullet.getEnumBullet())
            {
                isCheck = true;
            }
        }


        if (isCheck)
        {
            cc.log('飞机碰撞销毁 - enemy');
            this.playBomb(other);
            this.node.destroy();
        }
    },

    playBomb(other)
    {
        this._super(other);
        if (!!this.prefabCarry)
        {
            var obj = UtilGameObject.createAddparentByPrefabs(this.prefabCarry, this.node.parent);
            obj.x = this.node.x;
            obj.y = this.node.y;
        }
    }
});